package com.cat.enumerate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/sequential-digits/description/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/20 18:36
 * @since JDK17
 */

public class Solution01 {
    public List<Integer> sequentialDigits(int low, int high) {
        List<Integer> ans = new ArrayList<>();
        String s = "123456789";
        int n = Integer.toString(high).length();    //
        for (int i = Integer.toString(low).length(); i <= n; i++) {
            for (int l = 0, r = 0; r < 9; r++) {
                if (r - l + 1 < i) {    // 长度不够
                    continue;
                }
                int num = Integer.valueOf(s.substring(l, r + 1));   //
                if (num >= low && num <= high) {
                    ans.add(num);
                }
                l++;
            }
        }

        return ans;
    }
}
